package com.kiko.education.controller;

import com.kiko.education.model.Course;
import com.kiko.education.model.Score;
import com.kiko.education.service.CourseService;
import com.kiko.education.service.ScoreService;
import com.kiko.education.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class StudentRestConroller {

    @Autowired
    private UserService userService;
    @Autowired
    private CourseService courseService;
    @Autowired
    private ScoreService scoreService;

    //学生课程信息展示
    @RequestMapping(value="/courseList", method = RequestMethod.POST)
    public Map<String,Object> toCourseList(@RequestBody Map<String, Object> jsonData){
        String userID = jsonData.get("userID").toString();
        System.out.println(userID);
        List<Score> courseScoreList = scoreService.getCourseBySID(userID);
        Map<String,String> teaMap = new HashMap<>();
        Map<String,String> couTiMap = new HashMap<>();
        Map<String,String> couLoMap = new HashMap<>();
        Map<String,String> couNaMap = new HashMap<>();
        for(int i=0;i<courseScoreList.size();i++){
            Course course = courseService.getCourseByID(courseScoreList.get(i).getCourseID());
            String  teacher = userService.getByUserID(courseScoreList.get(i).getTeacherID()).getUserName();
            teaMap.put(String.valueOf(i), teacher);
            couNaMap.put(String.valueOf(i), course.getCourseName());
            couTiMap.put(String.valueOf(i), course.getCourseDate());
            couLoMap.put(String.valueOf(i), course.getCourseRoom());
        }
        Map<String,Object> results = new HashMap<>();
        results.put("couNames",couNaMap);
        results.put("couLocations",couLoMap);
        results.put("couTeachers",teaMap);
        results.put("couTimes",couTiMap);

        return results;
    }
}
